<!-- 差旅报销详情页面 -->
<template>
	<view>
		<u-sticky>
			<u-tabs
				class="tabs" 
				:list="tabsList" 
				@click="onTabClick"
				:scrollable="false" style="padding: 0 24rpx;background: #FFF;z-index:22;position: sticky;top: 0px;"
				:activeStyle="{color:'#171717', fontSize: '14px'}"
				:inactiveStyle="{color:'#C6C6C6', fontSize: '14px'}"
				:itemStyle="{ whiteSpace:'nowrap',height: '44px' }"
				lineColor="#1E6FFF"
			></u-tabs>
		</u-sticky>
		<view class="task_lists" :style="{ paddingBottom: tabvalue == '待办'?'130rpx':'0' }">
			<collapse name="基本信息" id="outside1" :maxHeight="maxHeight">
				<view class="listdefault" :id="uId">
					<view class="action">
						<view class="list1">单据编号</view>
						<view class="list2">{{ detailData.billNo }}</view>
					</view>
					<view class="action">
						<view class="list1">申请人</view>
						<view class="list2">{{ detailData.proposer_dictText }}</view>
					</view>
					<view class="action">
						<view class="list1">申请部门</view>
						<view class="list2">{{ detailData.proposerDeptId_dictText }}</view>
					</view>
					<view class="action">
						<view class="list1">申请时间</view>
						<view class="list2">{{ detailData.createTime }}</view>
					</view>
					<view class="action">
						<view class="list1">费用所属团队</view>
						<view class="list2">{{ detailData.teamId_dictText }}</view>
					</view>
					<view class="action">
						<view class="list1">申请公司</view>
						<view class="list2">{{ detailData.companyId_dictText }}</view>
					</view>
					<view class="action">
						<view class="list1">出差人员</view>
						<view class="list2">{{ detailData.employeeName }}</view>
					</view>
					<view class="action">
						<view class="list1">是否外聘人员</view>
						<view class="list2">{{ detailData.isExternalEngagedEmployee_dictText }}</view>
					</view>
					<view class="action">
						<view class="list1">外聘人员</view>
						<view class="list2">{{ detailData.externalPersonnel }}</view>
					</view>
					<view class="action">
						<view class="list1">单据类型</view>
						<view class="list2">{{ detailData.billCategory_dictText }}</view>
					</view>

					<view class="action">
						<view class="list1">费用所属年度</view>
						<view class="list2">{{ detailData.teamYear_dictText }}</view>
					</view>
					<view class="action">
						<view class="list1">团队费用类别</view>
						<view class="list2">{{ detailData.teamFeeCategory_dictText }}</view>
					</view>
					<view class="action">
						<view class="list1">是否关联项目</view>
						<view class="list2">{{ detailData.isRelProject_dictText }}</view>
					</view>
					<view class="action">
						<view class="list1">出差事由</view>
						<view class="list2">{{ detailData.travelReasons }}</view>
					</view>
				</view>
			</collapse>
			<action-collapse name="报销详情" :childFields="childFields1" id="outside2" :dataSource="childSource1">
				<view slot="label">
					<span style="font-weight: bold; font-size: 12px; color: rgba(0,0,0,.65);">报销明细费用累计：{{detailData.reimbursementAmount}}元</span>
					<span style=" font-size: 12px;color: rgba(0,0,0,.65);">（注：本次报销实际支付金额为报销明细费用累计。）</span>
				</view>
				<span slot="projectId_dictText" slot-scope="projectId" style="color: #1E6FFF;" @click="onClickProjectName(projectId.record)">{{projectId.text}}</span>
			</action-collapse>
			<action-collapse name="自驾公里数补助明细" :childFields="childFields2" id="outside3" :dataSource="childSource2">
				<view slot="label">
					<span style="font-weight: bold; font-size: 12px; color: rgba(0,0,0,.65);">自驾公里数补助明细费用累计：{{detailData.kilometresAmount}}元</span>
					<span style=" font-size: 12px;color: rgba(0,0,0,.65);">（注：自驾公里数补助累计不计入本次报销金额，使用油卡和定额提现方式兑现。）</span>
					<span slot="projectId_dictText" slot-scope="projectId" style="color: #1E6FFF;" @click="onClickProjectName(projectId.record)">{{projectId.text}}</span>
				</view>
			</action-collapse>
			<collapse name="结算信息" id="outside4" :maxHeight="maxHeight1">
				<view class="listdefault" :id="uId1">
					<view class="action">
						<view class="list1">结算方式</view>
						<view class="list2">{{ detailData.settleType_dictText }}</view>
					</view>
					<block v-if="detailData.settleType==0">
						<view class="action" >
							<view class="list1">收款户名</view>
							<view class="list2">{{ detailData.accountName }}</view>
						</view>
						<view class="action" >
							<view class="list1">收款开户行</view>
							<view class="list2">{{ detailData.bankName }}</view>
						</view>
						<view class="action" >
							<view class="list1">收款账号</view>
							<view class="list2">{{ detailData.accountNo }}</view>
						</view>
					</block>
					<block v-if="detailData.settleType==2">
						<view class="action" >
							<view class="list1">关联借款申请</view>
							<view class="list2">{{ detailData.loanBillId_dictText }}</view>
						</view>
						<view class="action" >
							<view class="list1">未还金额(元)</view>
							<view class="list2">{{ detailData.outstandingAmount }}</view>
						</view>
						<view class="action" >
							<view class="list1">支付金额(元)</view>
							<view class="list2">{{ detailData.paymentAmount }}</view>
						</view>
					</block>
				</view>
				
			</collapse>
			<default-list name="附件信息">
				<file-list :fileList="detailData.attachments"></file-list>
			</default-list>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>
<script>
	import actionCollapse from '@/pages/synergy/components/actionCollapse.vue'
	import detailInformationList from '@/pages/synergy/components/detailInformationList.vue'
	import fileList from '@/pages/synergy/components/fileList.vue'
	import collapse from '@/pages/synergy/components/collapse.vue'
	import defaultList from '@/pages/synergy/components/defaultList.vue'
	import flowList from '@/pages/synergy/components/flowList.vue'
	import {
		queryByIdReimBursement, // 根据id查询信息
		getProcessTaskTransInfo, // 查询流程流转信息
		getProcessHistoryList, // 查询流程图信息
		getProcessHistoryTaskList, // 查询历史流程图信息
		getNodePositionInfo, // 查询坐标信息数据
		rejectProcess, // 退回
		processComplete ,// 提交完成
		getChildrenListTravel, // 报销子表
		getChildrenListReimbursement // 公里数子表
	} from '@/api/index.js'
	import {
		BASE_URL
	} from '@/utils/baseUrl.js'
	import address from '@/utils/address.js'
	export default {
		data() {
			return {
				address: address,
				tabsList: [
					{ name: '基本信息',id: 'outside1' }, 
					{ name: '报销详情',id: 'outside2' },
					{ name: '自驾公里数补助明细',id: 'outside3' },
					{ name: '结算信息',id: 'outside4' },
				],
				detailData: {}, // 详情数据
				childFields1: { // 子表字段
					'项目名称': 'projectId_dictText',
					'任务分类': 'taskId_dictText',
					'任务说明': 'taskDescription',
					// '费用所属年度': 'teamYear',
					// '费用所属团队': 'teamId_dictText',
					'业绩归属年度': 'attributionYear',
					'出发时间': 'setOutTime',
					'回程时间': 'backTime',
					'出差天数': 'days',
					'出发地点': 'departurePlace_text',
					'到达地点': 'targetPlace_text',
					'报销内容': 'feeType_dictText',
					'交通方式': 'transportMode_dictText',
					'发票类型': 'isSpecial_dictText',
					'报销金额(元)': 'amount',
					'税费金额(元)': 'taxation',
					'未税金额(元)': 'untaxedAmount',
					'备注': 'remark',
				},
				childFields2: { // 子表字段
					'项目名称': 'projectId_dictText',
					'任务分类': 'taskId_dictText',
					'任务说明': 'taskDescription',
					// '费用所属年度': 'teamYear',
					// '费用所属团队': 'teamId_dictText',
					'业绩归属年度': 'attributionYear',
					'出发时间': 'setOutTime',
					'回程时间': 'backTime',
					'出差天数': 'days',
					'出发地点': 'departurePlace_text',
					'到达地点': 'targetPlace_text',
					'报销内容': 'selfDriving_dictText',
					'交通方式': 'selfDrivingMode_dictText',
					'出发里程数(km)': 'startMileage',
					'返程里程数(km)': 'endMileage',
					'里程数(km)': 'mileage',
					'补贴单价(元)': 'subsidyUnitPrice_dictText',
					'报销金额(元)': 'amount',
					'补助领款人': 'subsidyProposer_dictText',
					'备注': 'remark',
				},
				id:'',
				scrollTop: 0, // 滚动顶部距离
				tabvalue: '', // 协同首页tabs name
				childSource1: [], // 报销子表数据
				childSource2: [], // 公里数子表数据
				maxHeight: 0,
				maxHeight1: 0,
				uId: uni.$u.guid(),
				uId1: uni.$u.guid(),
			}
		},
		components: {
			actionCollapse,
			detailInformationList,
			fileList,
			collapse,
			defaultList,
			flowList
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onLoad(options) {
			this.id = options.id || ''
			this.loadData(this.id)
		},
		methods: {
			// 查询预立项申请详情
			loadData(id){
				queryByIdReimBursement({ id }).then(async res => {
					if(res.success){
						this.detailData = res.result
						this.getChildDataTravel(res.result.id)
						this.getChildDataReimbursement(res.result.id)
						this.timer = setTimeout(() => {
							clearTimeout(this.timer)
							this.timer = null
							this.$nextTick(() => {
								uni.createSelectorQuery().select('#'+this.uId).boundingClientRect(data => {
									this.maxHeight = data.height
								}).exec();
							})
							this.$nextTick(() => {
								uni.createSelectorQuery().select('#'+this.uId1).boundingClientRect(data => {
									this.maxHeight1 = data.height
								}).exec();
							})
						},300)
					} else {
						this.$refs.uToast.show({
							message: res.message,
							type: 'error'
						})
					}
				})
			},
			// 查询报销子表数据
			getChildDataTravel(id){
				var params = {
					column: 'createTime',
					order: 'desc',
					pageNo: 1,
					pageSize: 1000,
					billId: id,
					detailType: 1
				}
				getChildrenListTravel(params).then(res => {
					if(res.success){
						this.childSource1 = res.result.records || res.result || []
						if(this.childSource1.length > 0){
							this.childSource1.forEach(item => {
								item.departurePlace_text = this.handleAddress(item.departurePlace)
								item.targetPlace_text = this.handleAddress(item.targetPlace)
							})
						}
					}
				})
			},
			handleAddress(str){
				var arr = str.split(',')
				var addressDetail = ''
				this.address.map(value => {
					if (arr[0] && value.code == arr[0]) {
						addressDetail = value.name
						value.children.map(val => {
							if (arr[1] && val.code == arr[1]) {
								addressDetail = addressDetail + val.name
								val.children.map(item => {
									if (arr[2] && item.code == arr[2]) {
										addressDetail = addressDetail + item.name
									}
								})
							}
						})
					}
				})
				return addressDetail
			},
			// 查询子表数据
			getChildDataReimbursement(id){
				var params = {
					column: 'createTime',
					order: 'desc',
					pageNo: 1,
					pageSize: 1000,
					billId: id,
					detailType: 2
				}
				getChildrenListReimbursement(params).then(res => {
					if(res.success){
						this.childSource2 = res.result.records || res.result || []
						if(this.childSource2.length > 0){
							this.childSource2.forEach(item => {
								item.departurePlace_text = this.handleAddress(item.departurePlace)
								item.targetPlace_text = this.handleAddress(item.targetPlace)
							})
						}
					}
				})
			},
			// 点击tabs
			onTabClick (item) {
				uni.createSelectorQuery().in(this).select(`#${item.id}`).boundingClientRect(data => {
					uni.pageScrollTo({
						scrollTop:data.top + this.scrollTop - 54,
						duration: 150
					})
				 }).exec();
			},
			// 点击项目名称
			onClickProjectName (item) {
				uni.redirectTo({
					url: '/pages/reportFilesList/erpProjectReportListDetail?id=' + item.projectId
				})
			},
		}
	}
</script>
<style lang="scss" scoped>
@import "@/pages/synergy/common/action.scss";
.task_lists{
	padding: 20rpx 20rpx 0;
}
.image_lists{
	padding: 0 0 12rpx 12rpx;
	display: flex;
	flex-wrap: wrap;
	.image_list{
		margin-bottom: 20rpx;
		width: 144rpx;
		margin-right: 14rpx;
		.image_img{
			width: 116rpx;
			height: 116rpx;
			padding: 12rpx;
			background: rgba(0,0,0,0.0200);
			border-radius: 1px;
			border: 1px solid rgba(0,0,0,0.0800);
			position: relative;
			.image_action{
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translateX(-50%) translateY(-50%);
				width: 36rpx;
				height: 36rpx;
			}
			.image_source{
				width: 100%;
				height: 100%;
			}
		}
		.image_name{
			font-size: 10px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #B2B2B2;
			line-height: 28rpx;
			margin-top: 8rpx;
			text-align: left;
			overflow:hidden;
			white-space:nowrap;
			text-overflow:ellipsis;
			width: 152rpx;
		}
	}
}

.flow_right{
	display: flex;
	align-items: center;
	image{
		width: 40rpx;
		height: 40rpx;
	}
	text{
		font-size: 14px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #1E6FFF;
		line-height: 40rpx;
		margin-left: 4rpx;
	}
}

.task_bottom{
	display: flex;
	align-items: center;
	padding: 20rpx 0 20rpx 52rpx;
	background-color: #FFFFFF;
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	z-index: 10000;
	.task_bottom_write{
		display: flex;
		align-items: center;
		image{
			width: 48rpx;
			height: 48rpx;
			margin-right: 8rpx;
		}
		text{
			font-size: 14px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #7F7F7F;
			line-height: 40rpx;
		}
	}
	.refuse{
		width: 168rpx;
		height: 90rpx;
		line-height: 90rpx;
		background: rgba(0,0,0,0.0500);
		border-radius: 10rpx;
		margin: 0 16rpx 0 52rpx;
		font-size: 17px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(0,0,0,0.5000);
		text-align: center;
	}
	.agree{
		width: 318rpx;
		height: 90rpx;
		line-height: 90rpx;
		background: #1E6FFF;
		border-radius: 10rpx;
		font-size: 17px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		text-align: center;
	}
}
</style>
